package shooting.ui.missilepattern
{
	import flash.geom.Point;
	
	import shooting.ui.MissileContainer;
	import shooting.ui.missile.IMissile;
	import shooting.ui.missile.MissaleBase;
	
	public class MissalePatternBase implements IMissilePattern
	{
		private var objectContainer:MissileContainer;
		private var _direction:Number;
		private var _kind:String;
		private var _angleRange:Number;
		private var _count:uint;
		private var _speed:Number;
		private var _interval:Number;
		private var _accSpeed:Number;
		private var _accAngle:Number;
		private var _position:Point;
		private var _renderCount:uint;
		
		private var temAngle:Number;
		private var temDirection:Number;
		
		public function MissalePatternBase(kind:String, position:Point, direction:Number, speed:Number = 1, interval:uint = 30, accSpeed:Number = 0, accAngle:Number = 0, angleRange:Number = 0, count:uint = 1)
		{
			_direction = direction;
			_kind = kind;
			_angleRange = angleRange;
			_count = count;
			_speed = speed;
			_interval = interval;
			_accSpeed = accSpeed;
			_accAngle = accAngle;
			_position = position;
			
			temAngle = _angleRange / _count;
			temDirection = _direction + (temAngle/2) - (_angleRange/2)+ 90;
			temAngle = temAngle / 180 * Math.PI;
			temDirection = temDirection  / 180 * Math.PI;
			
			_renderCount = 0;
		}

		public function get angle():Number
		{
			return _direction;
		}
		
		public function set angle(r:Number):void
		{
			_direction = r;
		}
		
		public function setContainer(container:MissileContainer):void
		{
			objectContainer = container;
		}
		
		public function render():void
		{
			_renderCount++;
			
			if( (_renderCount % _interval) == 0)
			{
				var i:uint;
				for(i = 0; i < _count; i++)
				{
					var speed:Number = _speed + ( _accSpeed * _renderCount);
					var direct:Number = temDirection + (_accAngle * _renderCount) + (temAngle * i);
					var ms:IMissile = new MissaleBase(_kind, _position.clone(), speed, direct);
					objectContainer.addMissile(ms);
				}
			}
		}
		
	}
}